local Lua__baoxian = fk.CreateSkill {

  name = "Lua__baoxian",

  tags = { Skill.Compulsory, },

}

Fk:loadTranslationTable{
  ["Lua__baoxian"] = "保险",
  [":Lua__baoxian"] = "锁定技，你造成或受到伤害后，若你有“货”，你随机弃置一张“货”，摸两张牌。",
}

Lua__baoxian:addEffect(fk.Damage, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(Lua__baoxian.name) and
               #player:getPile("$huo") > 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        -- 随机弃置一张“货”
        local huo = player:getPile("$huo")
        if #huo > 0 then
            local to_throw = {huo[math.random(1, #huo)]}
            room:throwCard(to_throw, Lua__baoxian.name, player, player)
            -- 摸两张牌
            player:drawCards(2, Lua__baoxian.name)
        end
    end,
})
Lua__baoxian:addEffect(fk.Damaged, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(Lua__baoxian.name) and
               #player:getPile("$huo") > 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        -- 随机弃置一张“货”
        local huo = player:getPile("$huo")
        if #huo > 0 then
            local to_throw = {huo[math.random(1, #huo)]}
            room:throwCard(to_throw, Lua__baoxian.name, player, player)
            -- 摸两张牌
            player:drawCards(2, Lua__baoxian.name)
        end
    end,
})

return Lua__baoxian